import { FormSchema } from '/@/components/Table';
import { BasicColumn } from '/@/components/Table';
// import { formatToDateTime } from '/@/utils/dateUtil';
import { PageCustomerInputDto, CustomersServiceProxy,IdInput } from '/@/services/ServiceProxies';
import { useI18n } from '/@/hooks/web/useI18n';
const { t } = useI18n();

export const searchFormSchema: FormSchema[] = [
  {
    field: 'filter',
    label: t('common.key'),
    component: 'Input',
    colProps: { span: 8 },
  },
];

export const tableColumns: BasicColumn[] = [
  {
    title: t('routes.basic.customer.name'),
    dataIndex: 'customerName',
  },
  {
    title: t('routes.basic.customer.province'),
    dataIndex: 'province',
  },
  {
    title: t('routes.basic.customer.city'),
    dataIndex: 'city',
  },
  {
    title: t('routes.basic.customer.detailAddress'),
    dataIndex: 'location',
    width:500
  }
];
 
export const createFormSchema: FormSchema[] = [
  {
    field: 'customerName',
    label: t('routes.basic.customer.name'),
    component: 'Input',
    required: true,
    colProps: { span: 18 },
  },
  {
    field: 'province',
    component: 'Select',
    label: t('routes.basic.customer.province'),
    colProps: {
      span: 18,
    },
    componentProps: ({ formModel, formActionType }) => {
      return {
        options: provincesOptions,
        placeholder: t('common.chooseText'), 
        onChange: (e: any) => {
           console.log(e)
          let citiesOptions = citiesOptionsData[e];
          console.log(citiesOptions)
          if (e === undefined) {
            citiesOptions = [];
          }
          formModel.city = undefined; //  reset city value
          const { updateSchema } = formActionType;
          updateSchema({
            field: 'city',
            componentProps: {
              options: citiesOptions,
            },
          });
        },
      };
    },
  },
  {
    field: 'city',
    component: 'Select',
    label: t('routes.basic.customer.city'),
    colProps: {
      span: 18,
    },
    componentProps: {
      options: [], // defalut []
      placeholder: t('common.chooseText'),
    },
  },
  {
    field: 'location',
    label: t('routes.basic.customer.detailAddress'),
    component: 'InputTextArea',
    required: false,
    colProps: { span: 24 },
  }
];


export async function createAsync({ params }) {
  const customersServiceProxy = new CustomersServiceProxy();
  await customersServiceProxy.create(params);
}

export async function deleteAsync({ id }) {
  const customersServiceProxy = new CustomersServiceProxy();
  const request = new IdInput ();
  request.id = id;
  await customersServiceProxy.delete(request);
}
 
export async function getTableListAsync(params: PageCustomerInputDto) {
  const customersServiceProxy = new CustomersServiceProxy();
  return customersServiceProxy.page(params);
}

export async function getChinaAsync() {
  const customersServiceProxy = new CustomersServiceProxy();

  var data =await customersServiceProxy.china();
  provincesOptions=data.provinceData;
  citiesOptionsData=data.cityData;
  console.log(data);

  //return customersServiceProxy.china();
}
 
var provincesOptions =[] as any;
var citiesOptionsData=[] as any;
   
// const provincesOptions = [
//   {
//     id: 'guangdong',
//     label: '广东省',
//     value: '1',
//     key: '1',
//   },
//   {
//     id: 'jiangsu',
//     label: '江苏省',
//     value: '2',
//     key: '2',
//   },
// ];
// const citiesOptionsData = {
//   guangdong: [
//     {
//       label: '珠海市',
//       value: '1',
//       key: '1',
//     },
//     {
//       label: '深圳市',
//       value: '2',
//       key: '2',
//     },
//     {
//       label: '广州市',
//       value: '3',
//       key: '3',
//     },
//   ],
//   jiangsu: [
//     {
//       label: '南京市',
//       value: '1',
//       key: '1',
//     },
//     {
//       label: '无锡市',
//       value: '2',
//       key: '2',
//     },
//     {
//       label: '苏州市',
//       value: '3',
//       key: '3',
//     },
//   ],
// };